const navTo = (url, data, type = "navigateTo") => {
	// url参数拼接
	url += (url.indexOf('?') < 0 ? '?' : '&') + param(data)
	if (type === "navigateTo") {
		uni.navigateTo({ url })
	} else if (type === "reLaunch") {
		uni.reLaunch({ url })
	} else if (type === "switchTab") {
		uni.switchTab({ url })
	} else if (type === "redirectTo") {
		uni.redirectTo({ url })
	}
}
// 返回上一页
const navBack = () => { uni.navigateBack() }
// 格式化参数对象
function param(data) {
	if(JSON.stringify(data) === "{}" || !data){
		return "";
	}
	let url = ''
	for (var k in data) {
		let value = data[k] !== undefined ? data[k] : ''
		url += '&' + k + '=' + encodeURIComponent(value)
	}
	return url ? url.substring(1) : ''
}
export { navTo, navBack }